#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.template.defaultfilters import linebreaks, safe
from django.core.urlresolvers import reverse
from pkoltutils.context_processors import exclude_context
from snippets.models import Snippet

class SnippetContainer(object):
    def __init__(self, filter, header, content):
        self.header = header
        self.content = safe(content) if filter else linebreaks(content)
        
    def __unicode__(self):
        return self.content

@exclude_context(reverse('admin:index'))
def context(request):
    snippets = Snippet.objects.filter(publish=True)
    snippets_dict = {}
    for snippet in snippets:
        snippets_dict[snippet.slug] = SnippetContainer(snippet.filter, snippet.header, snippet.content)
    return {'snippets': snippets_dict}